#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#define PATH_FIFO "/home/yujiu/fifo"
void if_error(int,char*);
int main(){
	int res=0;
	res=access(PATH_FIFO,F_OK);
	if_error(res,"access");	
	int fd=open(PATH_FIFO,O_RDONLY);
	if_error(fd,"read");
	char buf[128];
	ssize_t byte =0;
	while((byte=read(fd,buf,sizeof(buf)))>0){
		printf("read:%s\n",buf);
		memset(buf,0,sizeof(buf));
	}
	close(fd);
	return 0;
}
void if_error(int res,char* str){
	if(res==-1){           
        perror(str);  
        exit(1);           
	}   
}
